package com.financialsharing.common;


import com.financialsharing.pojo.User;
import com.financialsharing.util.JwtUtil;

import javax.servlet.http.HttpServletRequest;

/**
 * @author administrator
 */
public class UserUtil {

    /***
     * 获取用户id
     * @param request
     * @return
     */
    public static Integer getUserId(HttpServletRequest request){
        String token = request.getHeader("Authorization");
        String jwt = token.substring(token.lastIndexOf(" ")+1);
        User u = JwtUtil.unsign(jwt,User.class);
        return u.getId();
    }

    /**
     * 获取角色id
     * @param request
     * @return
     */
    public static Integer getRoleId(HttpServletRequest request){
        String token = request.getHeader("Authorization");
        String jwt = token.substring(token.lastIndexOf(" ")+1);
        User u = JwtUtil.unsign(jwt,User.class);
        return u.getRoleId();
    }
}
